from flask import Flask, render_template
from models import db
import click
from flask.cli import with_appcontext
from api import bp as api_bp

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///bills.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db.init_app(app)
app.register_blueprint(api_bp)

@app.cli.command("init-db")
@with_appcontext
def init_db():
    """Initialize the database."""
    db.create_all()
    click.echo('Initialized the database.')

@app.route('/')
def index():
    """前端页面入口"""
    return render_template('index.html')

if __name__ == '__main__':
    app.run( debug=True )